<template>
    <div class="main">
      <div v-if="rightsButtons['add']" class="filter-container">
        <router-link :to="{name: 'activityPartnerAdd'}" class="filter-item fr">
          <el-button type="success" icon="el-icon-plus">新建</el-button>
        </router-link>
      </div>
      <el-table :data="list" v-loading="listLoading" element-loading-text="给我一点时间" border highlight-current-row>
        <el-table-column align="center" label="名称" prop="name"></el-table-column>
        <el-table-column align="center" label="购买等级">
          <template slot-scope="scope">
            <template v-for="(item, index) in scope.row.buyRole.split(',')">
              <span v-if="item==='0'" :key="index">普通{{index===scope.row.buyRole.split(',').length-1?'':'、'}}</span>
              <span v-if="item==='1'" :key="index">兰蜜{{index===scope.row.buyRole.split(',').length-1?'':'、'}}</span>
              <span v-if="item==='2'" :key="index">大区{{index===scope.row.buyRole.split(',').length-1?'':'、'}}</span>
              <span v-if="item==='3'" :key="index">董事{{index===scope.row.buyRole.split(',').length-1?'':'、'}}</span>
            </template>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="120" v-if="rightsButtons['edit']">
          <template slot-scope="scope">
            <router-link :to="{name: 'activityPartnerEdit', params: {id: scope.row.id}}">
              <el-button type="primary" size="mini">编辑</el-button>
            </router-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container" v-if="listTotal > 0">
        <el-pagination @current-change="handleCurrentChange" :current-page.sync="listQuery.pageIndex" :page-size="listQuery.pageSize" :total="listTotal" layout="total, prev, pager, next, jumper"></el-pagination>
      </div>
    </div>
</template>
<script>
    export default {
        name: 'activityPartner',
        data(){
            return {
                listQuery: {
                    userId: this.$store.getters.userId,
                    /*isPage: 1,
                    pageIndex: 1,
                    pageSize: 20*/
                },
                listLoading: false,
                listTotal: 0,
                list: []
            }
        },
        created(){
            this.getList();
        },
        methods: {
            getList(){
                this.listLoading = true;
                this.request({
                    url: '/bsnl-product/partnergoods/list',
                    //url: '/partnergoods/list',
                    method: 'get',
                    params: this.listQuery
                }).then(({data, totalCount}) => {
                    this.list = data;
                    this.listTotal = totalCount;
                    this.listLoading = false;
                }).catch(err => {
                    console.log(err);
                    this.list = [];
                    this.listTotal = 0;
                    this.listLoading = false;
                });
            },
            // 切换分页
            handleCurrentChange(page) {
                this.listQuery.pageIndex = page;
                this.getList();
            },
        }
    }
</script>
